package com.hyl.servlet;

import com.hyl.entity.ComputerRoom;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "ComputerServlet",urlPatterns = "/list")
public class ComputerServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、获取请求的数据
		//2、操作
		//3、页面跳转 / 响应
		List<ComputerRoom> list = new ArrayList<>();
		for(int i=1;i<=5;i++){
			ComputerRoom tmp = new ComputerRoom(i,
					"机房2-"+i,
					i*10/3,
					"张三",
					"4号楼",
					i%3+1);
			list.add(tmp);
		}
		request.setAttribute("list", list);
		request.getRequestDispatcher("list.jsp").forward(request, response);
	}
}
